<template>
	<view>
		<button @click="go" type="warn">跳转</button>
	</view>
	<view class="">
		<view class="">
			解构后全局数据：{{count}}
		</view>
		<view class="">
			{{store.count}} - {{store.doubleCount}}
		</view>
		<view class="">
			{{store.obj}}
		</view>
		<view class="">
			<button @click="store.add"> 修改 store 数据-同步</button>
			<button @click="store.sub"> 修改 store 数据-异步</button>
			<button @click="change"> 直接修改store 数据</button>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		ref
	} from 'vue'
	import { storeToRefs } from 'pinia'
	// 导入封装的request
	// 说明：@指向项目根目录
	import request from '@/utils/request.js'

	// 1. 导入获取 count-store 的函数
	import { useCount } from '@/stores/count.js'

	// 2. 获取 store
	const store = useCount()
	console.log('count-store:', store);
	//  问题：直接解构 store 对象中的全局数据, 会失去响应式
	// const { count } = store
	// 解决：调用storeToRefs，然后解构（了解）
	const { count } = storeToRefs(store)

	const change = () => {
		store.count = 2000
		store.obj.age = 100
	}

	const getUser = async () => {
		request.get('/driver/users')
	}
	onLoad(() => {
		getUser()
		uni.utils.message('你好')
	})

	const go = () => {
		// uni.utils.push('/pages/login/index')
		uni.utils.push('/pages/my/index')
	}
</script>

<style lang='scss' scoped>

</style>